package com.ruoyi.web.controller.market.account;

import java.util.List;
import java.util.Map;

import com.ruoyi.account.enums.WeiXinUserIdEnum;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.db.domain.AccountInfo;
import com.ruoyi.account.service.IAccountInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.wapper.AccountInfoWapper;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 总账号信息Controller
 * 
 * @author ruoyi
 * @date 2023-02-02
 */
@Controller
@RequestMapping("/account/info")
public class AccountInfoController extends BaseController
{
    private String prefix = "account/info";

    @Autowired
    private IAccountInfoService accountInfoService;

    @RequiresPermissions("account:info:view")
    @GetMapping()
    public String info()
    {
        return prefix + "/info";
    }

    /**
     * 查询总账号信息列表
     */
    @RequiresPermissions("account:info:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AccountInfo accountInfo)
    {
        startPage();
        List<Map<String, Object>> mapList = accountInfoService.selectAccountInfoListMap(accountInfo);

        Map<String, Object> totalMap = accountInfoService.selectAccountInfoAllListMap(accountInfo);
        mapList.add(0,totalMap);

        mapList = new AccountInfoWapper(mapList).wrap();
        return getDataTable(mapList);
    }

    /**
     * 导出总账号信息列表
     */
    @RequiresPermissions("account:info:export")
    @Log(title = "总账号信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AccountInfo accountInfo)
    {
        List<AccountInfo> list = accountInfoService.selectAccountInfoList(accountInfo);
        ExcelUtil<AccountInfo> util = new ExcelUtil<AccountInfo>(AccountInfo.class);
        return util.exportExcel(list, "总账号信息数据");
    }

    /**
     * 新增总账号信息
     */
    @GetMapping("/add")
    public String add(ModelMap modelMap)
    {
        List<Map<String, String>> weixinUserIdMapList = WeiXinUserIdEnum.getListMap();
        modelMap.put("wxUserIdList", weixinUserIdMapList);
        return prefix + "/add";
    }

    /**
     * 新增保存总账号信息
     */
    @RequiresPermissions("account:info:add")
    @Log(title = "总账号信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AccountInfo accountInfo)
    {
        return toAjax(accountInfoService.insertAccountInfo(accountInfo));
    }

    /**
     * 修改总账号信息
     */
    @RequiresPermissions("account:info:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        AccountInfo accountInfo = accountInfoService.selectAccountInfoById(id);
        mmap.put("accountInfo", accountInfo);

        List<Map<String, String>> weixinUserIdMapList = WeiXinUserIdEnum.getListMap();
        mmap.put("wxUserIdList", weixinUserIdMapList);

        return prefix + "/edit";
    }

    /**
     * 修改保存总账号信息
     */
    @RequiresPermissions("account:info:edit")
    @Log(title = "总账号信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AccountInfo accountInfo)
    {
        return toAjax(accountInfoService.updateAccountInfo(accountInfo));
    }

    /**
     * 删除总账号信息
     */
    @RequiresPermissions("account:info:remove")
    @Log(title = "总账号信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(accountInfoService.deleteAccountInfoByIds(ids));
    }
}
